package com.rede.didiok.user.modulelist.file.service.impl;

import java.io.File;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import com.rede.didiok.common.dto.admin.SystemConfigDto;
import com.rede.didiok.user.modulelist.file.annotation.UploadType;
import com.rede.didiok.user.modulelist.file.entity.FileCategoryEntity;
import com.rede.didiok.user.modulelist.file.enums.UploadTypeEnum;
import com.rede.didiok.user.modulelist.file.util.QiniuUtil;


/**
 * 七牛云实现类
 *
 * @author 陌溪
 * @since 2020年1月20日20:05:45
 */
@Service
@RefreshScope
@Slf4j
@UploadType({UploadTypeEnum.QINIU_UPLOAD})
public class QiniuServiceImpl extends AbstractUploadFile {
    @Autowired
    QiniuUtil qiniuUtil;


    @Override
    public String uploadFile(SystemConfigDto systemConfig, File tempFile, FileCategoryEntity fileSort, String newFileName) {
        try {
            return qiniuUtil.uploadQiniu(tempFile, systemConfig, newFileName);
        } catch (Exception e) {
            log.error("上传七牛云失败！", e);
        }
        return "";
    }

    @Override
    public String deleteFile(String fileName, SystemConfigDto systemConfig) {
        return qiniuUtil.deleteFile(fileName, systemConfig);
    }
}
